package com.dj.uphome.web.service.system.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dj.common.web.service.impl.BaseCrudServiceImpl;
import com.dj.uphome.web.mapper.system.SysRoleUserMapper;
import com.dj.uphome.web.service.system.SysRoleUserService;
import com.dj.uphome.web.vo.system.SysRoleUserVo;
import com.dj.uphome.web.vo.system.SysRoleVo;

@Service
public class SysRoleUserServiceImpl extends BaseCrudServiceImpl<SysRoleUserVo> implements SysRoleUserService {
	@Autowired
	private SysRoleUserMapper sysRoleUserMapper;
	@Transactional
	public void create(int userId, int[] roleIds) throws Exception {
		sysRoleUserMapper.deleteByUserId(userId);
		List<SysRoleUserVo> list = new ArrayList<>();
		if (null != roleIds && roleIds.length > 0) {
			for (int roleId : roleIds) {
				SysRoleUserVo vo = new SysRoleUserVo();
				vo.setRoleId(roleId);
				vo.setUserId(userId);
				list.add(vo);
			}
		}
		sysRoleUserMapper.batchSave(list);
	}

	public List<SysRoleVo> listAllForAuthorize(int userId) throws Exception {
		return sysRoleUserMapper.listAllForAuthorize(userId);
	}

}
